package io.agora;


import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

import java.io.IOException;
import java.util.Base64;

//import java.net.http.HttpClient;
//import java.net.http.HttpRequest;
//import java.net.http.HttpResponse;


// 基于 Java 实现的 HTTP 基本认证示例，使用 RTC 的服务端 RESTful API
public class Base64Encoding {

    public static void main(String[] args) throws IOException, InterruptedException {

        // 客户 ID
        final String customerKey = "edeb8b91d15a415396d3d779bae15333";
        // 客户密钥
        final String customerSecret = "83eae6df2e284dd0bc1415d1d0a4c351";

        // 拼接客户 ID 和客户密钥并使用 base64 编码
        String plainCredentials = customerKey + ":" + customerSecret;
        String base64Credentials = new String(Base64.getEncoder().encode(plainCredentials.getBytes()));
        // 创建 authorization header
        String authorizationHeader = "Basic " + base64Credentials;

        HttpRequest httpRequest = HttpUtil.createGet("https://api.agora.io/dev/v1/projects");
        httpRequest.header("Authorization", authorizationHeader)
                .header("Content-Type", "application/json");
        HttpResponse execute = httpRequest.execute();
        System.out.println(execute.body());

//        HttpClient client = HttpClient.newHttpClient();
//
//        // 创建 HTTP 请求对象
//        HttpRequest request = HttpRequest.newBuilder()
//                .uri(URI.create("https://api.agora.io/dev/v1/projects"))
//                .GET()
//                .header("Authorization", authorizationHeader)
//                .header("Content-Type", "application/json")
//                .build();
//        // 发送 HTTP 请求
//        HttpResponse<String> response = client.send(request,
//                HttpResponse.BodyHandlers.ofString());
//
//        System.out.println(response.body());
    }
}